<?php  

/**
 * Capital Direct Lending (http://www.philbsd.com/cdl)
 *
 * Copyright (C) 2008 Philippine Business Solution Developers <http://www.philbsd.com>
 * All rights reserved.
 *
 *
 * LICENSE
 *
 * This source file is subject to the GNU General Public License v3 license
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-3.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@philbsd.com so we can send you a copy immediately.
 *
 * @copyright  (c) 2008 Philippine Business Solution Developers. (http://www.philbsd.com)
 * @license    http://www.gnu.org/licenses/gpl-3.0.txt
 * @version    $Id: SB_Controller.php 73 2008-03-29 18:35:14Z artiskool $
 */

if (!defined('BASEPATH')) exit('No direct script access allowed');

class SB_Controller extends Controller
{
	protected $_data = array();
	protected $_swordPost = array();

    public function __construct()
    {
		parent::Controller();
		$this->load->library('layout', 'layout/main.shtml');
		$this->_data['titleForLayout'] = $this->config->item('site_title');
		$this->_data['baseUrl'] = $this->config->item('base_url');
		$this->_initializeInputs();
    }

	public function render($view, $data = array(), $layout = 'main.shtml', $return = false)
	{
		$layout = "layout/$layout";
		$this->_data['contentForLayout'] = $this->load->view($view, array_merge($data, $this->_data), true);		
		if ($return) {
			return $this->load->view($layout, $this->_data, true);
		} else {
			$this->load->view($layout, $this->_data, false);
		}
	}
	
	protected function _initializeInputs()
	{
		$this->_swordPost = array();
		foreach ($_POST as $k => $v) {
			$x = explode('/', $k);
			if (!isset($x[1])) {
				continue;
			}
			if (!isset($this->_swordPost[$x[0]])) {
				$this->_swordPost[$x[0]] = array();
			}
			$this->_swordPost[$x[0]][$x[1]] = $v;
		}
	}

	public function _unlinkIfExists($filename)
	{
		if (file_exists($filename)) {
			unlink($filename);
		}
	}
}
